package client;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


/**
 * 
 * @author Quentin, Vincent, Charlie
 *
 */
public class ColorPicker extends JFrame implements ChangeListener, ActionListener {
	
	private static final long serialVersionUID = 7116305445795066612L;
	
	private JColorChooser leColor;
	
	private Gestionnaire_Client gc;
	private boolean fg;
	
	private JButton ok;
	
	/**
	 * Constructeur
	 * @param gc
	 * @param fg true=couleur FG, couleur BG sinon
	 */
	public ColorPicker(Gestionnaire_Client gc, boolean fg) {
		this.setSize(500,500);
		this.gc = gc;
		this.fg = fg;
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setTitle("Choisissez une couleur");
		
		JPanel lePan=new JPanel();
		lePan.setLayout(new BorderLayout());
		
		leColor=new JColorChooser(Color.white);
		leColor.getSelectionModel().addChangeListener(this);
		leColor.removeChooserPanel(leColor.getChooserPanels()[2]);
		
		ok=new JButton("Valider");
		ok.addActionListener(this);
		JPanel panButton=new JPanel();
		panButton.add(ok);
		
		lePan.add(leColor,BorderLayout.CENTER);
		lePan.add(panButton,BorderLayout.SOUTH);
		this.add(lePan);
		this.setVisible(true);
	}

	/**
	 * Changement d'état
	 */
	public void stateChanged(ChangeEvent e)
	{
		if (fg == true)
		{
			gc.setColorPickedFG(leColor.getColor());
			
		}
		else
		{
			gc.setColorPickedBG(leColor.getColor());
		}
		gc.updatePreviewColors();
	}


	@Override
	public void actionPerformed(ActionEvent arg0)
	{
		this.dispose();
	}

}